package pers.dawnyang.modular.system.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import pers.dawnyang.common.domain.Result;
import pers.dawnyang.common.util.ResultUtil;
import pers.dawnyang.modular.system.domain.request.operLog.OperLogReqR;
import pers.dawnyang.modular.system.domain.response.operLog.OperLogRes;
import pers.dawnyang.modular.system.service.OperLogService;

/**
 * 操作日志记录
 * 
 * @author: dawn yang
 * @date: 2020-08-24 10:22:03
 * 
 */

@Controller
@RequestMapping("/sys/operLog")
public class OperLogController {

  @Autowired
  private OperLogService operLogService;

  @RequiresPermissions("sys:operLog:index")
  @GetMapping("/index")
  public String index() {
    return "sys/operLog/index";
  }

  @RequiresPermissions("sys:operLog:detail")
  @GetMapping("/detail")
  public String detailView(String id, ModelMap model) {
    OperLogRes operLogRes = operLogService.getDetail(id);
    model.put("model", JSON.toJSONString(operLogRes));
    return "sys/operLog/detail";
  }

  @RequiresPermissions("sys:operLog:list")
  @PostMapping("/getPage")
  @ResponseBody
  public Result<Page<OperLogRes>> getPage(Page<OperLogRes> page, OperLogReqR req) {
    Page<OperLogRes> resPage = operLogService.getPage(page, req);
    return ResultUtil.success(resPage);
  }

}
